package com.tiza.xiaoyoubao.ui.fragment;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.orhanobut.hawk.Hawk;
import com.squareup.picasso.Picasso;
import com.tianze.library.base.BaseFragment;
import com.tiza.xiaoyoubao.R;
import com.tiza.xiaoyoubao.app.Constants;
import com.tiza.xiaoyoubao.entity.AdvancesCompleteInfo;
import com.tiza.xiaoyoubao.entity.DnTBTaskOrderInfo;
import com.tiza.xiaoyoubao.entity.MpTmTaskOrderInfo;
import com.tiza.xiaoyoubao.entity.TaskAllInfo;
import com.tiza.xiaoyoubao.entity.TaskOperateInfo;
import com.tiza.xiaoyoubao.entity.TaskOrderInfo;
import com.tiza.xiaoyoubao.entity.TaskRebatesInfo;
import com.tiza.xiaoyoubao.entity.TaskShipMentsInfo;
import com.tiza.xiaoyoubao.net.ApiHttpClient;

import butterknife.BindView;

/**
 * Created by mapple on 17/4/14.
 * 手机天猫任务详情2
 */

public class MpTmTaskDetail2Fragment extends BaseFragment {

    @BindView(R.id.iv_image)
    ImageView iv_image;
    @BindView(R.id.tv_shopName)
    TextView tv_shopName;
    @BindView(R.id.tv_shopDescribe)
    TextView tv_shopDescribe;
    @BindView(R.id.tv_keyWord)
    TextView tv_keyWord;
    @BindView(R.id.tv_cJPrice)
    TextView tv_cJPrice;
    @BindView(R.id.tv_num)
    TextView tv_num;
    @BindView(R.id.tv_taskType)
    TextView tv_taskType;
    @BindView(R.id.tv_buyNumber)
    TextView tv_buyNumber;
    @BindView(R.id.tv_receiving)
    TextView tv_receiving;
    @BindView(R.id.tv_location)
    TextView tv_location;
    @BindView(R.id.tv_city)
    TextView tv_city;
    @BindView(R.id.tv_priceInterval)
    TextView tv_priceInterval;
    @BindView(R.id.tv_orderMessage)
    TextView tv_orderMessage;
    @BindView(R.id.tv_additionalRequest)
    TextView tv_additionalRequest;
    @BindView(R.id.tv_showPrice)
    TextView tv_showPrice;
    private AdvancesCompleteInfo advancesCompleteInfo;
    private TaskOperateInfo taskOperateInfo;
    private TaskRebatesInfo taskRebatesInfo;
    private TaskShipMentsInfo taskShipMentsInfo;
    private TaskAllInfo taskAllInfo;
    private MpTmTaskOrderInfo mpTmTaskOrderInfo;
    Bundle args;
    private String state;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        args = getArguments();
        state = args.getString("state");
    }


    @Override
    protected int getLayoutId() {
        return R.layout.fragment_mp_tm_task_detail2;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        switch (state) {
            case "AdvancesComplate":
                AdvancesComplate();
                break;
            case "operate":
                Operate();
                break;
            case "rebates":
                Rebates();
                break;
            case "shipments":
                Shipments();
                break;
            case "orderTask":
                OrderTask();
                break;
            case "allTask":
                AllTask();
                break;
            default:
                break;
        }
    }

    /**
     * 已完成
     */
    public void AdvancesComplate() {
        advancesCompleteInfo = (AdvancesCompleteInfo) args.getSerializable("info");
        tv_shopName.setText(advancesCompleteInfo.getShopName().replaceFirst(advancesCompleteInfo.getShopName().substring(0, 1), "*"));
        if (advancesCompleteInfo.getTitle().length() <= 15) {
            tv_shopDescribe.setText(advancesCompleteInfo.getTitle());
        } else {
            tv_shopDescribe.setText("***" + advancesCompleteInfo.getTitle().substring(15, advancesCompleteInfo.getTitle().length()));
        }
        tv_keyWord.setText(advancesCompleteInfo.getKeywords());
        tv_cJPrice.setText(advancesCompleteInfo.getPrice());
        tv_showPrice.setText(advancesCompleteInfo.getMobilePrice());
        tv_num.setText(advancesCompleteInfo.getNumber());
        tv_taskType.setText(advancesCompleteInfo.getTypeName());
        tv_buyNumber.setText(advancesCompleteInfo.getNumber());
        Picasso.with(mActivity).load(ApiHttpClient.URL2 + advancesCompleteInfo.getImages()).placeholder(
                R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv_image);
        if (advancesCompleteInfo.getLocation().equals("xiaoliang")) {
            tv_receiving.setText("销量");
        } else if (advancesCompleteInfo.getLocation().equals("zhitongche")) {
            tv_receiving.setText("直通车");
        } else if (advancesCompleteInfo.getLocation().equals("zonghe")) {
            tv_receiving.setText("综合");
        }
        tv_location.setText(advancesCompleteInfo.getReceiving());
        tv_city.setText(advancesCompleteInfo.getCity());
        if (!TextUtils.isEmpty(advancesCompleteInfo.getMinPrice())) {
            tv_priceInterval.setText(advancesCompleteInfo.getMinPrice()+"-"+advancesCompleteInfo.getMaxPrice());
        } else {
            tv_priceInterval.setText("");
        }
        tv_orderMessage.setText(advancesCompleteInfo.getMessage());
        if (TextUtils.isEmpty(advancesCompleteInfo.getRemarks())) {
            tv_additionalRequest.setText("商家无其他要求");
        } else {
            tv_additionalRequest.setText(advancesCompleteInfo.getRemarks());
        }

    }

    /**
     * 待操作
     */
    public void Operate() {
        taskOperateInfo = (TaskOperateInfo) args.getSerializable("info");
        tv_shopName.setText(taskOperateInfo.getShopName().replaceFirst(taskOperateInfo.getShopName().substring(0, 1), "*"));
        if (taskOperateInfo.getTitle().length() <= 15) {
            tv_shopDescribe.setText(taskOperateInfo.getTitle());
        } else {
            tv_shopDescribe.setText("***" + taskOperateInfo.getTitle().substring(15, taskOperateInfo.getTitle().length()));
        }
        tv_keyWord.setText(taskOperateInfo.getKeywords());
        tv_cJPrice.setText(taskOperateInfo.getPrice());
        tv_showPrice.setText(taskOperateInfo.getMobilePrice());
        tv_num.setText(taskOperateInfo.getNumber());
        tv_taskType.setText(taskOperateInfo.getTypeName());
        tv_buyNumber.setText(taskOperateInfo.getNumber());
        Picasso.with(mActivity).load(ApiHttpClient.URL2 + taskOperateInfo.getImages()).placeholder(
                R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv_image);
        if (taskOperateInfo.getLocation().equals("xiaoliang")) {
            tv_receiving.setText("销量");
        } else if (taskOperateInfo.getLocation().equals("zhitongche")) {
            tv_receiving.setText("直通车");
        } else if (taskOperateInfo.getLocation().equals("zonghe")) {
            tv_receiving.setText("综合");
        }
        tv_location.setText(taskOperateInfo.getReceiving());
        tv_city.setText(taskOperateInfo.getCity());
        if (!TextUtils.isEmpty(taskOperateInfo.getMinPrice())) {
            tv_priceInterval.setText(taskOperateInfo.getMinPrice()+"-"+taskOperateInfo.getMaxPrice());
        } else {
            tv_priceInterval.setText("");
        }
        tv_orderMessage.setText(taskOperateInfo.getMessage());
        if (TextUtils.isEmpty(taskOperateInfo.getRemarks())) {
            tv_additionalRequest.setText("商家无其他要求");
        } else {
            tv_additionalRequest.setText(taskOperateInfo.getRemarks());
        }

    }

    /**
     * 待操作(订单任务)
     */
    public void OrderTask() {
        mpTmTaskOrderInfo = (MpTmTaskOrderInfo) args.getSerializable("info");
        tv_shopName.setText(mpTmTaskOrderInfo.getShopName().replaceFirst(mpTmTaskOrderInfo.getShopName().substring(0, 1), "*"));
        if (mpTmTaskOrderInfo.getTitle().length() <= 15) {
            tv_shopDescribe.setText(mpTmTaskOrderInfo.getTitle());
        } else {
            tv_shopDescribe.setText("***" + mpTmTaskOrderInfo.getTitle().substring(15, mpTmTaskOrderInfo.getTitle().length()));
        }
        tv_keyWord.setText(mpTmTaskOrderInfo.getKeywords());
        tv_cJPrice.setText(mpTmTaskOrderInfo.getPrice());
        tv_showPrice.setText(mpTmTaskOrderInfo.getMobilePrice());
        tv_num.setText(mpTmTaskOrderInfo.getNumber());
        tv_taskType.setText(mpTmTaskOrderInfo.getTypeName());
        tv_buyNumber.setText(mpTmTaskOrderInfo.getNumber());
        Picasso.with(mActivity).load(ApiHttpClient.URL2 + mpTmTaskOrderInfo.getImages()).placeholder(
                R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv_image);
        if (mpTmTaskOrderInfo.getLocation().equals("xiaoliang")) {
            tv_receiving.setText("销量");
        } else if (mpTmTaskOrderInfo.getLocation().equals("zhitongche")) {
            tv_receiving.setText("直通车");
        } else if (mpTmTaskOrderInfo.getLocation().equals("zonghe")) {
            tv_receiving.setText("综合");
        }
        tv_location.setText(mpTmTaskOrderInfo.getReceiving());
        tv_city.setText(mpTmTaskOrderInfo.getCity());
        if (!TextUtils.isEmpty(mpTmTaskOrderInfo.getMinPrice())) {
            tv_priceInterval.setText(mpTmTaskOrderInfo.getMinPrice()+"-"+mpTmTaskOrderInfo.getMaxPrice());
        } else {
            tv_priceInterval.setText("");
        }
        tv_orderMessage.setText(mpTmTaskOrderInfo.getMessage());
        if (TextUtils.isEmpty(mpTmTaskOrderInfo.getRemarks())) {
            tv_additionalRequest.setText("商家无其他要求");
        } else {
            tv_additionalRequest.setText(mpTmTaskOrderInfo.getRemarks());
        }
    }

    /**
     * 待返款
     */
    public void Rebates() {
        taskRebatesInfo = (TaskRebatesInfo) args.getSerializable("info");
        tv_shopName.setText(taskRebatesInfo.getShopName().replaceFirst(taskRebatesInfo.getShopName().substring(0, 1), "*"));
        if (taskRebatesInfo.getTitle().length() <= 15) {
            tv_shopDescribe.setText(taskRebatesInfo.getTitle());
        } else {
            tv_shopDescribe.setText("***" + taskRebatesInfo.getTitle().substring(15, taskRebatesInfo.getTitle().length()));
        }
        tv_keyWord.setText(taskRebatesInfo.getKeywords());
        tv_cJPrice.setText(taskRebatesInfo.getPrice());
        tv_showPrice.setText(taskRebatesInfo.getMobilePrice());
        tv_num.setText(taskRebatesInfo.getNumber());
        tv_taskType.setText(taskRebatesInfo.getTypeName());
        tv_buyNumber.setText(taskRebatesInfo.getNumber());
        Picasso.with(mActivity).load(ApiHttpClient.URL2 + taskRebatesInfo.getImages()).placeholder(
                R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv_image);
        if (taskRebatesInfo.getLocation().equals("xiaoliang")) {
            tv_receiving.setText("销量");
        } else if (taskRebatesInfo.getLocation().equals("zhitongche")) {
            tv_receiving.setText("直通车");
        } else if (taskRebatesInfo.getLocation().equals("zonghe")) {
            tv_receiving.setText("综合");
        }
        tv_location.setText(taskRebatesInfo.getReceiving());
        tv_city.setText(taskRebatesInfo.getCity());
        if (!TextUtils.isEmpty(taskRebatesInfo.getMinPrice())) {
            tv_priceInterval.setText(taskRebatesInfo.getMinPrice()+"-"+taskRebatesInfo.getMaxPrice());
        } else {
            tv_priceInterval.setText("");
        }
        tv_orderMessage.setText(taskRebatesInfo.getMessage());
        if (TextUtils.isEmpty(taskRebatesInfo.getRemarks())) {
            tv_additionalRequest.setText("商家无其他要求");
        } else {
            tv_additionalRequest.setText(taskRebatesInfo.getRemarks());
        }
    }

    /**
     * 发货中
     */
    public void Shipments() {
        taskShipMentsInfo = (TaskShipMentsInfo) args.getSerializable("info");
        tv_shopName.setText(taskShipMentsInfo.getShopName().replaceFirst(taskShipMentsInfo.getShopName().substring(0, 1), "*"));
        if (taskShipMentsInfo.getTitle().length() <= 15) {
            tv_shopDescribe.setText(taskShipMentsInfo.getTitle());
        } else {
            tv_shopDescribe.setText("***" + taskShipMentsInfo.getTitle().substring(15, taskShipMentsInfo.getTitle().length()));
        }
        tv_keyWord.setText(taskShipMentsInfo.getKeywords());
        tv_cJPrice.setText(taskShipMentsInfo.getPrice());
        tv_showPrice.setText(taskShipMentsInfo.getMobilePrice());
        tv_num.setText(taskShipMentsInfo.getNumber());
        tv_taskType.setText(taskShipMentsInfo.getTypeName());
        tv_buyNumber.setText(taskShipMentsInfo.getNumber());
        Picasso.with(mActivity).load(ApiHttpClient.URL2 + taskShipMentsInfo.getImages()).placeholder(
                R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv_image);
        if (taskShipMentsInfo.getLocation().equals("xiaoliang")) {
            tv_receiving.setText("销量");
        } else if (taskShipMentsInfo.getLocation().equals("zhitongche")) {
            tv_receiving.setText("直通车");
        } else if (taskShipMentsInfo.getLocation().equals("zonghe")) {
            tv_receiving.setText("综合");
        }
        tv_location.setText(taskShipMentsInfo.getReceiving());
        tv_city.setText(taskShipMentsInfo.getCity());
        if (!TextUtils.isEmpty(taskShipMentsInfo.getMinPrice())) {
            tv_priceInterval.setText(taskShipMentsInfo.getMinPrice()+"-"+taskShipMentsInfo.getMaxPrice());
        } else {
            tv_priceInterval.setText("");
        }
        tv_orderMessage.setText(taskShipMentsInfo.getMessage());
        if (taskAllInfo.getRemarks().equals(" ")) {
            tv_additionalRequest.setText("商家无其他要求");
        } else {
            tv_additionalRequest.setText(taskShipMentsInfo.getRemarks());
        }

    }


    /**
     * 待确认
     */
    public void AllTask() {
        taskAllInfo = (TaskAllInfo) args.getSerializable("info");
        tv_shopName.setText(taskAllInfo.getShopName().replaceFirst(taskAllInfo.getShopName().substring(0, 1), "*"));
        if (taskAllInfo.getTitle().length() <= 15) {
            tv_shopDescribe.setText(taskAllInfo.getTitle());
        } else {
            tv_shopDescribe.setText("***" + taskAllInfo.getTitle().substring(15, taskAllInfo.getTitle().length()));
        }
        tv_keyWord.setText(taskAllInfo.getKeywords());
        tv_cJPrice.setText(taskAllInfo.getPrice());
        tv_showPrice.setText(taskAllInfo.getMobilePrice());
        tv_num.setText(taskAllInfo.getNumber());
        tv_taskType.setText(taskAllInfo.getTypeName());
        tv_buyNumber.setText(taskAllInfo.getNumber());
        Picasso.with(mActivity).load(ApiHttpClient.URL2 + taskAllInfo.getImages()).placeholder(
                R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv_image);
        if (taskAllInfo.getLocation().equals("xiaoliang")) {
            tv_receiving.setText("销量");
        } else if (taskAllInfo.getLocation().equals("zhitongche")) {
            tv_receiving.setText("直通车");
        } else if (taskAllInfo.getLocation().equals("zonghe")) {
            tv_receiving.setText("综合");
        }
        tv_location.setText(taskAllInfo.getReceiving());
        tv_city.setText(taskAllInfo.getCity());
        if (!TextUtils.isEmpty(taskAllInfo.getMinPrice())) {
            tv_priceInterval.setText(taskAllInfo.getPriceSection());
        } else {
            tv_priceInterval.setText("");
        }
        tv_orderMessage.setText(taskAllInfo.getMessage());
        if (TextUtils.isEmpty(taskAllInfo.getRemarks())) {
            tv_additionalRequest.setText("商家无其他要求");
        } else {
            tv_additionalRequest.setText(taskAllInfo.getRemarks());
        }
    }
}
